<template>
  <div class="app-container">
    <div class="app-container_conter">
    <div style="display: flex;justify-content:space-between">

      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="雇员姓名" prop="name">
          <el-input
              v-model="queryParams.name"
              placeholder="请输入雇员姓名"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item label="证件号码" prop="id_card_no">
          <el-input
              v-model="queryParams.id_card_no"
              placeholder="请输入证件号码"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" size="mini" @click="handleQuery">搜索</el-button>
          <el-button type="info"  size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <div style="margin-bottom: 20px">
        <el-button type="primary" @click="getBack">返回</el-button>
      </div>
    </div>
    <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain
                     size="mini"
                     :disabled="multiple"
                     @click="getReject">驳回</el-button>
        </el-col>
<!--          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--        </div>-->
<!--      </div>-->

    </el-row>



    <el-table v-loading="loading" :data="userList"   :header-cell-style="tableHeaderColor" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="保单号" align="center" prop="insure_no" fixed min-width="180px"/>
<!--      <el-table-column label="保单号" align="center" prop="insureEli.insureNo"/>-->
      <el-table-column label="雇员姓名" align="center" prop="name" min-width="100px"/>
      <!--      <el-table-column label="用户性别" align="center" prop="sex" :formatter="sexFormat" />-->
      <el-table-column label="证件名称" align="center" prop="id_card_type_name" min-width="120px"/>
      <el-table-column label="证件号码" align="center" prop="id_card_no" min-width="170px"/>
<!--      :formatter="typeFormat"-->
      <el-table-column label="工种类别" align="center" prop="type" min-width="100px" />
      <!--      <el-table-column label="健康情况" align="center" prop="healthCond"/>-->
<!--      <el-table-column label="月收入" align="center" prop="income_month"/>-->
      <el-table-column label="用工单位" align="center" prop="company" min-width="170px"/>
      <el-table-column label="职务名称" align="center" prop="industry_name" min-width="150px"/>
<!--      <el-table-column label="保费" align="center" prop="price"/>-->
      <el-table-column label="创建时间" align="center" prop="create_time" min-width="150px"/>
      <el-table-column label="用户类型" align="center" prop="is_approve_user" min-width="100px"/>
            <el-table-column label="状态 " align="center" prop="status2" min-width="100px" />
      <el-table-column label="操作" align="center" fixed="right" min-width="100px" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button
              size="mini"
              type="text"
              v-hasPermi="['api:Insurance:reject_user']"
              @click="getReject(scope.row)"
          >驳回
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    </div>
    <pagination
        style="background: transparent"
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

    <el-dialog

        :title="dialog3.title"
        :visible.sync="dialog3.dialogVisible"
        width="50%"
    >
      <div >
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="原因" prop="content">
            <el-input v-model="form.content" placeholder="请填写驳回原因" type="textarea"
                      :rows="3" style="width: 400px"></el-input>
          </el-form-item>

          <!--      <el-form-item>-->
          <!--        <el-button>取消</el-button>-->
          <!--        <el-button type="primary" @click="onSubmit">确认</el-button>-->

          <!--      </el-form-item>-->
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
     <el-button type="primary" @click="dialog3.dialogVisible = false">取消</el-button>
    <el-button type="primary" @click="getRejection">确认</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>

import {review_member_list,reject_user} from "@/api/insurancemanagement/auditor"


export default {
name: "detailsPersons",
  components: {

  },
  data() {
    return {
      dialog3:{
        title:'驳回原因',
        dialogVisible:false,
      },
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 投保用户表格数据
      userList: [],

      // 状态 字典
      statusOptions: [],
      //证件类型
      idCardTypeList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,//页码
        pageSize: 10,//条数
        name: null,//雇员姓名
        id_card_no: null,//证件号码
        // insureNo:null,
        type: null,//工种类型
        isApproveUser:'',//用户类型
        company:null,//用工单位
        plan_id:null,//方案id
        insure_id:null,
      },
      //驳回原因
      form:{
        content:null,//驳回原因
        customer_id:null,// 用户id
        user_id:null,// 操作人id
      },
      rules:{
        content: [
          {required: true, message: '请输入驳回原因', trigger: 'blur'},
        ],
      },
      //工种类型
      TypeworkId: [],
      //用户类型
      ApproveUser:[
        {
          id:true,
          name:'批单用户'
        },
        {
          id:false,
          name:'出单用户'
        }
      ],

    };
  },

  created() {
    this.form.user_id=JSON.parse(localStorage.getItem('userInfo')).userId;
    var insureInfo = this.$route.query.insureInfo;
    console.log('insureInfo', insureInfo)
    if (insureInfo != undefined) {
      this.queryParams.company = insureInfo.company;
      this.queryParams.plan_id = insureInfo.plan_id;
      this.queryParams.insure_id=insureInfo.insure_id
      this.queryParams.type = insureInfo.type;
    }
    console.log('form', this.form)

    this.getList();

    this.getDicts("common_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("industry_type").then(response => {
      this.TypeworkId = response.data;
      console.log('TypeworkId', this.TypeworkId)
    });


  },
  methods: {
    /* 修改表头颜色 */
    tableHeaderColor({ rowIndex }) {
      if (rowIndex === 0) {
        return 'background-color: #304156;color: #fff;font-weight: 400;font-family: Microsoft YaHei;'
      }
    },
    //返回上一页
    getBack() {
      this.$router.back(-1);
    },
    //点击驳回按钮
    getReject(item){
    this.form.customer_id=item.id || this.ids
      this.dialog3.dialogVisible=true
    },
    //选择工种名称
    selectDepart(e) {
      this.form.industryName = e.name
    },
    /** 查询投保用户列表 */
    getList() {
      console.log('queryParams', this.queryParams);
      this.loading = true;
      review_member_list(this.queryParams).then(response=>{
        console.log('responsess3534',response)
      })
      review_member_list(this.queryParams).then(response => {
        console.log('response查询所有', response)
        this.userList = response.data.data;
        // for (var i=0;i<this.userList.length;i++){
        //   if (this.userList[i].isApproveUser){
        //     this.userList[i].isApproveUser='批单用户'
        //   }else {
        //     this.userList[i].isApproveUser='出单用户'
        //   }
        // }
        this.total = response.data.count;
        this.loading = false;
        console.log('total', typeof this.total)

      });
    },
    //点击确认按钮驳回提交
    getRejection(){
      var that=this
      console.log('form',this.form)
      this.$refs["form"].validate(valid => {
        if (valid) {
          console.log(365346)
          this.$alert('您是否确认将这些人员驳回？', '标题名称', {
                  confirmButtonText: '确定',
                  callback: action => {
                    if (action=='confirm'){
                      reject_user(that.form).then(res=>{
                        that.$message({
                          message: res.msg,
                          type: 'success'
                        });
                        that.getList();
                        this.dialog3.dialogVisible=false
                        console.log('驳回',res)
                      })

                    }
                  }
                });

        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      // this.reset();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.queryParams.id_card_no=null
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.multiple = !selection.length
    },

  }
}
</script>

<style scoped>
.app-container_conter{
  background: #F8FBFF;
  padding:30px;
  border-radius: 10px;
  box-sizing: border-box;
}
</style>
